package com.ws.test08.test;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 王硕
 * @version jdk21
 * @className test
 * @description
 * @date 2024/11/21 21:38
 */
public class test {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("aaa");
        list.add("bbb");
        list.add("aaa");
        list.add("abc");
        list.add("xyz");
        list.add("123");
        list.add("xyz");

        List<String> distinctList = new ArrayList<>();

        for (String item : list) {
            // 检查新List中是否已经包含了当前元素
            if (!distinctList.contains(item)) {
                distinctList.add(item);
            }
        }

        for (int i = 0; i < distinctList.size(); i++) {
            System.out.println(distinctList.get(i));
        }
    }
}
